# -*- coding: utf-8 -*-
# @Time    : 2020/9/14 12:25
# @Author  : liuwenfan
# @File    : group_service.py
# @Software: PyCharm
from application import db
from application.models.mantis_models import MantisProjectTable, MantisProjectHierarchyTable


def get_project(group_id):
    # sql = "select p.id,p.name " \
    #       "from mantis_project_table as p,mantis_project_hierarchy_table as h " \
    #       "where p.id = h.child_id and h.parent_id=%s"
    ret = db.session.query(MantisProjectTable.id, MantisProjectTable.name).join(MantisProjectHierarchyTable,
                                                                                MantisProjectTable.id == MantisProjectHierarchyTable.child_id).filter(
        MantisProjectHierarchyTable.parent_id == group_id).all()
    data = [{"project_id": i, "project_name": j} for i, j in ret]
    for o in range(len(data)):
        if data[o]['project_name'] == '产 品 库':
            data[o]['project_name'] = '产品库'
    
    return data
